/**
 * @param {number[]} piles
 * @param {number} k
 * @return {number}
 */
 var minStoneSum = function(piles, k) {
  const queue = new MaxPriorityQueue()
  for(const x of piles){
    queue.enqueue(x, x)
  }
  const sum = piles.reduce((pre,cur) => pre+cur, 0)
  let cost = 0
  while(k--){
    let { element } = queue.dequeue()
    cost += Math.floor(element/2)
    element -= Math.floor(element/2)
    queue.enqueue(element,element)
  }
  return sum - cost
};
